package com.itheima.search;

public class SearchDemo02 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 5, 7, 8, 9, 5};
        int search = search(arr, 1);
        System.out.println(search);

    }

    //二分查找
    public static int search(int[] arr,int value){
        int left = 0;
        int right = arr.length-1;
        int mid = (left+right)/2;
        while (left<=right){
            mid = (left+right)/2;
            if(arr[mid]>value){
                right = mid-1;
            } else if (arr[mid]<value) {
                left = mid+1;
            }else{
                return mid;
            }
        }


            return -1;

    }
}
